name: Prepare
description: Install dependencies and build the platform
inputs:
  build:
    description: Build the production bundle of the platform
    required: false
    default: 'true'
  registry:
    description: NPM registry to set up for auth
    required: false

runs:
  using: composite
  steps:
    - name: Install Node.js
      uses: actions/setup-node@v4
      with:
        node-version: 18
        registry-url: ${{ inputs.registry }}

    - uses: pnpm/action-setup@v3
      name: Install pnpm
      id: pnpm-install
      with:
        run_install: false

    - name: Get cache info
      id: cache-info
      shell: bash
      run: |
        echo "os-release=$(node --eval 'console.log(os.release())')" >> $GITHUB_OUTPUT
        echo "pnpm-cache-dir=$(pnpm store path)" >> $GITHUB_OUTPUT

    - uses: actions/cache@v4
      name: Setup pnpm cache
      with:
        path: ${{ steps.cache-info.outputs.pnpm-cache-dir }}
        key:
          ${{ runner.os }}-${{ steps.cache-info.outputs.os-release }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
        restore-keys: |
          ${{ runner.os }}-${{ steps.cache-info.outputs.os-release }}-pnpm-store-

    - name: Install dependencies
      shell: bash
      run: pnpm install

    - name: Build
      if: inputs.build == 'true'
      shell: bash
      run: pnpm run build
      env:
        npm_config_workspace_concurrency: '1'
        NODE_OPTIONS: --max_old_space_size=6144
